﻿using System;
using System.Collections.Generic;
using FrameworkManapro.BusinessModel;

namespace GMAC.ReportingSystem.Business.Components
{
    public class BankComponent : IBusinessComponent<Entities.Bank>
    {
        private DataAccess.BankDataAccess dac;

        #region IBusinessComponent<Bank> Members

        public int Create(GMAC.ReportingSystem.Business.Entities.Bank entityToCreate)
        {
            if (ValidateFields(entityToCreate))
                return dac.Insert(entityToCreate);

            return 0;
        }

        public int Delete(GMAC.ReportingSystem.Business.Entities.Bank entityToDelete)
        {
            if (ValidateId(entityToDelete))
                return dac.Delete(entityToDelete);

            return 0;
        }

        public int Edit(GMAC.ReportingSystem.Business.Entities.Bank entityToEdit)
        {
            if (ValidateId(entityToEdit))
                return dac.Update(entityToEdit);

            return 0;
        }

        /*GMAC.ReportingSystem.Business.Entities.Bank IBusinessComponent<GMAC.ReportingSystem.Business.Entities.Bank>.GetDetails(object entityId)
        {
            throw new NotImplementedException();
        }*/

        #endregion

        # region Constructor

        public BankComponent()
        {
            dac = new DataAccess.BankDataAccess();
        }

        #endregion

        # region Public Methods

        //public Entities.BankCollection Search(string codeBank, string name, decimal?  CostReceivable, string BankNumber, string CollectingAccount)
        //{
        //    if (name == null)
        //        name = String.Empty;
        //    if (codeBank == null)
        //        codeBank = String.Empty;
        //    if (BankNumber == null)
        //        BankNumber = String.Empty;
        //    if (CollectingAccount == null)
        //        CollectingAccount = String.Empty;
        //    return dac.Search(codeBank, name, CostReceivable, BankNumber, CollectingAccount);
        //}

        public Entities.Bank GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        public Entities.BankCollection GetList()
        {
            return dac.GetList();
        }
        //public Entities.BankCollection GetbyCode(string code)
        //{
        //    return dac.GetbyCode(code);
        //}
        //public Entities.Bank GetbyBankNumber(string BankNumber)
        //{
        //    return dac.GetbyBankNumber(BankNumber);
        //}
        # endregion

        # region Private Methods

        private bool ValidateFields(Entities.Bank entityToValidate)
        {
            //if (string.IsNullOrEmpty(entityToValidate.Code))
            //    throw new ArgumentNullException("Code Bank", "The argument cannot be null.");
            //if (string.IsNullOrEmpty(entityToValidate.Name))
            //    throw new ArgumentException("Bank Name", "The argument cannot be null");

            return true;
        }

        private bool ValidateId(Entities.Bank entityToValidate)
        {
            if (entityToValidate.BankId <= 0)
                throw new ArgumentOutOfRangeException("BankID", "Value must be greater than zero.");

            return true;
        }

        # endregion

    }
}
